define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/order/index' + location.search,
                    add_url: 'user/order/add',
                    edit_url: 'user/order/edit',
                    // del_url: 'user/order/del',
                    // multi_url: 'user/order/multi',
                    import_url: 'user/order/import',
                    table: 'user_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
                        {
                            field: 'type', title: __('Type'), searchList: {
                            '0': __('待定'),
                            '1': __('商城'),
                            '2': __('现货')
                        },
                            formatter: Table.api.formatter.status
                        },
                        {field: 'total', title: __('Total'), operate: false},
                        {field: 'give_money', title: __('赠送金额'), operate: false},
                        {field: 'total_money', title: __('剩余额度'), operate: false},
                        {
                            field: 'images',
                            title: __('验证图片'),
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.images
                        },
                        // {field: 'user_id', title: __('User_id')},
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {
                                '-1': __('拒绝'),
                                '0': __('待上传图片'),
                                '1': __('待审核'),
                                '2': __('已通过'),
                                '3': __('已参与'),
                                '5': __('已失效')
                            },
                            formatter: Table.api.formatter.status
                        },
                        {field: 'mark', title: __('Mark'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'edit', //唯一标识、权限标识
                                    text: '审核', //按钮显示的文字，支持function
                                    title: '审核', //按钮显示的文字，支持function
                                    classname: 'btn btn-info btn-xs btn-dialog', //按钮的class，支持btn-dialog/btn-ajax/btn-addtabs
                                    url: 'user/order/edit/ids/{id}', //按钮的链接，支持使用{字段名}来占位替换，支持function
                                    disable: function (row) {
                                        if (row.status == 1) {
                                            return false;
                                        } else {
                                            return true;
                                        }
                                    },
                                    extend: '', //扩展的扩展属性，FastAdmin1.4.0+支持function
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
